/**
 * 初始化详情对话框
 */
var HotListInfoDlg = {
    hotListInfoData : {},
};

/**
 * 清除数据
 */
HotListInfoDlg.clearData = function() {
    this.hotListInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
HotListInfoDlg.set = function(key, val) {
    this.hotListInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
HotListInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
HotListInfoDlg.close = function() {
    parent.layer.close(window.parent.HotList.layerIndex);
}

/**
 * 收集数据
 */
HotListInfoDlg.collectData = function() {
    this
    .set('id')
    .set('seq')
    .set('imageSrc')
    .set('jumpType')
    .set('appId')
    .set('appUrl')
    .set('h5Url')
    .set('detail')
    .set('createTime')
    .set('createId')
    .set('appIdKey')
    .set('title')
    .set('description');
    
    var jumpType =$('input[name="jumpType"]:checked').val();
    this.hotListInfoData['jumpType'] = jumpType; 
    
    this.hotListInfoData['detail'] = HotListInfoDlg.editor.txt.html();
    
    var themeImage=$("#themeImage").val();
    
    this.hotListInfoData['themeImage'] = themeImage;
    
	var appid = localStorage.getItem("appid");//获取存储的变量key的值 
	if(appid){
		 this.hotListInfoData['appIdKey'] = appid;
	}
   
}

/**
 * 提交添加
 */
HotListInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/hotList/add", function(data){
        Feng.success("添加成功!");
        window.parent.HotList.table.refresh();
        HotListInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.hotListInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
HotListInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/hotList/update", function(data){
        Feng.success("修改成功!");
        window.parent.HotList.table.refresh();
        HotListInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.hotListInfoData);
    ajax.start();
}

$(function() {

	 // 初始化头像上传
    var avatarUp = new $WebUpload("imageSrc");
    avatarUp.setUploadBarId("progressBar");
    avatarUp.setMultiple(true);
    avatarUp.init();
    
    //初始化编辑器
    var E = window.wangEditor;
    var editor = new E('#detail');
    editor.create();
    editor.txt.html($("#contentVal").val());
    HotListInfoDlg.editor = editor;
    
    
    var html="";
	var themeImage = $("#themeImage").val();
	if(themeImage !=null && themeImage!=''){ 
		debugger
		var themeImageArr = themeImage.split(",");
		$.each(themeImageArr, function(i,val){  
			html += '<div class="report-name" style="margin-left:0px;" > <img src="'+ val +'"  style="width:92px;height:92px;margin:0 10px 10px 0;"> <a href=\'javascript:void(0)\' onclick="deleteImgae(this)"  alt="删除"  type=\'button\'> <div class="deletImage">x</div> <input type="hidden" name="imageHidden" value="'+val+'"> </a> </div>';
			 
	    });     
		$("#imageThumbnail").html(html);   
	}
});
